package com.zhang.controller.communication;

import com.zhang.common.util.result.R;
import com.zhang.common.util.result.RUtils;
import com.zhang.communication.entity.ChatMessage;
import com.zhang.communication.service.IChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户消息表 前端控制器
 * </p>
 *
 * @author 创世神
 * @since 2024-06-07
 */
@RestController
@RequestMapping("/communication/chat/message")
public class ChatMessageController {
    @Autowired
    private IChatMessageService messageService;

    @PostMapping
    public void createConversation(@RequestBody ChatMessage message) {
        messageService.sendMessage(message);
    }

    @GetMapping("list")
    public R getMessageList(@RequestParam String anotherId) {
        List<ChatMessage> messages = messageService.getChatWithAnotherMessages(anotherId);
        return RUtils.successData(messages);
    }
}
